home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Communications / General / LineShare Folder / Put Onto Productions Disks / LineShare Scripts / Fax Class1&ARA&Data < prev    next >
Text File  |  1994-04-28  |  8KB  |  444 lines

  1. ! Version 3.0.2
  2. !
  3. !$ Use this script with Class 1 fax software working in the "numeric answers"
  4. !$ mode (FaxSTF,Faxilitate), ARA 1.0 or 2.0,
  5. !$ and a BBS, E-mail or other communication server software
  6. !
  7. !$ This script allows to place fax AND ARA/data calls, and it allows to receive
  8. !$ fax OR ARA/data calls.
  9. !
  10. !$ A cable for hardware handshaking is required
  11.  
  12. ^# Modem:
  13. ^2 Fax Software:     = Enum("FaxSTF™"="0","Faxilitate"="1") "0"
  14. ^3 Error Correction: = Bool("Enabled"="AUTO","Disabled"="NORM") "NORM"
  15. ^4 Incoming Calls:   = Enum("Fax"="0","ARA/Data"="1") "1"
  16. ^5 Data Port Speed:  = Enum("9600","19200","38400") "19200"
  17. ! ------------------------------------------
  18. ! Resetting the modem:
  19. ! ------------------------------------------
  20. @Hangup
  21.   SetTries 2
  22.   Flush
  23.   HsReset 0,0,17,19,0,0
  24. !
  25. ! Try to catch the "OK" answer, use the Escape seq and DTR transitions
  26. ! to enter the command mode
  27. !
  28. @Label 1
  29.   matchclr
  30.   matchstr 1 2 "OK\r\n"
  31.   write "ATH0V1Q0\r"
  32.   matchread 20
  33.   ChrDelay 1
  34.   Write "+++"
  35.   ChrDelay 0
  36.   DtrClear
  37.   SBreak
  38.   DtrSet
  39. !
  40.   DecTries
  41.   IfTries 0 1
  42. !
  43. ! OSErr -6019 "Modem error - the modem is not responding"
  44. !
  45.   exit -6019
  46. @Label 2
  47.   SetVar A "&F"
  48.   GetOption A "DFLT" 3
  49. @Label 3
  50.   write "AT^A+FCLASS=0\r"
  51.   Jsr 100
  52.   exit 0
  53.  
  54. @Label 6
  55.   Say "This script cannot be used with this modem"
  56.   ifOriginate 9
  57.   pause 1800
  58. @Label 9
  59.   exit -6019
  60.  
  61. ! ------------------------------------------
  62. !    Receiving incoming calls
  63. ! ------------------------------------------
  64. @ANSWER
  65. !
  66. ! Set the modem preferred speed first
  67.   SerReset 19200,0,8,1
  68.   Jsr 80
  69.  
  70. @Label 10
  71. !
  72. ! Set the common options
  73.   Jsr 70
  74.  
  75. !
  76. ! Go to Fax receive if required
  77. !
  78.   ifStr 4 40 "0"
  79. !
  80. ! ARA/Data call waiting
  81. !
  82. !
  83. ! Set the desired speed
  84.   SerReset Val("^5"),0,8,1
  85.   Jsr 80
  86. !
  87. ! Set the data options
  88.   Jsr 75
  89.  
  90.   GetCommand B "Data" "M"
  91.   GetCommand C "Data" "L"
  92.   GetCommand D "Data" "S0"
  93.   SetVar A "S0=2"
  94.   ifStr D 16 "S0=0"
  95.   ifStr D 16 ""
  96.   SetVar A "^D"
  97. @Label 16
  98. !
  99. ! Set the speaker and S0
  100.   Write "AT^A^B^C\r"
  101.   Jsr 100
  102. !
  103. ! Everything is ready - let's sit and wait for a data call
  104. ! We'll wait for 2 minutes, then reinitiate the modem
  105. !
  106.   Note "Waiting for an ARA/DATA call…"
  107.   Jsr 90
  108.   IfStr C 10 "NONE"
  109.  
  110.   IfOpen "Data" 21
  111.   Jump 30
  112. @Label 21
  113.   IfOpen "ARA" 22
  114.   Jump 35
  115. @Label 22
  116.   Note "Waiting for an ARA frame"
  117.   MatchClr
  118.   MatchStr 1 23 "^$\r"
  119.   MatchStr 2 28 "\08\01\03\14\04\03\00\08\250\16\03"
  120.   MatchStr 3 29 "\01\27\02\29\01\02\01\06"
  121.   MatchRead 40
  122.   Jump 24
  123. @Label 23
  124.   QueueInput "^$\r"
  125. @Label 24
  126.   Note "Non-ARA call"
  127.   Jump 35
  128.  
  129. @Label 28
  130.   Note "ARA 1.0 call"
  131.   Jump 30
  132. @Label 29
  133.   Note "ARA 2.0 call"
  134.   Jump 30
  135.  
  136. @Label 30
  137.   QueueInput "\r\nCARRIER ^B\r\n"  
  138.   IfStr A 31 "NONE"
  139.   IfStr A 31 "None"
  140.   QueueInput "\r\nREL\r\n"
  141. @Label 31
  142.   IfOriginate 32
  143.   QueueInput "\r\nRING\r\n"
  144. @Label 32
  145.   Attach "ARA" (DTR)
  146.  
  147. @Label 35
  148.   GetSReg C "DATA" 4
  149.   QueueInput "\r^CCONNECT ^B\r^C"
  150.   ifOriginate 36
  151.   QueueInput "\r^CRING\r^C"
  152. @Label 36
  153.   HsReset 0,1,17,19,0,1
  154.   Attach "Data" (DTR,Escape,Break)
  155.  
  156. !
  157. ! Receiving Fax calls
  158. !
  159. @Label 40
  160.   Write "AT+FCLASS=1\r"
  161.   Jsr 100
  162. !
  163. ! Get the Speaker and the Ring Num options
  164.   GetCommand B "Fax" "M"
  165.   GetCommand C "Fax" "L"
  166.   GetCommand D "Fax" "S0"
  167.   SetVar A "S0=2"
  168.   ifStr D 41 "S0=0"
  169.   ifStr D 41 ""
  170.   SetVar A "^D"
  171. @Label 41
  172. !
  173. ! Set the speaker and S0, switch to the numeric mode.
  174.   Write "AT^A^B^CV0\r"
  175.   Jsr 110
  176. !
  177. ! Everything is ready - let's sit and wait for a fax call
  178. ! We'll wait for 2 minutes, then reinitiate the modem
  179.   Note "Waiting for a fax call…"
  180.   Jsr 85
  181.   IfStr C 49 "NONE"
  182. !
  183. ! Fax connection has been established (we read "CONNECT")
  184. ! Put the CONNECT ("1\r") back to the buffer,
  185. ! if it was an incoming call, put the "RING" before it
  186. @Label 45
  187.   QueueInput "1\r"
  188.   ifOriginate 47
  189. @Label 46
  190.   QueueInput "2\r2\r"
  191. @Label 47
  192.   Attach "Fax" (DTR,Reset(2400),IdleLimit=30)
  193.  
  194. @Label 49
  195.   Write "ATV1\r"
  196.   Jsr 100
  197.   Jump 40
  198. ! ------------------------------------------
  199. ! Originating a call through the "ARA" subport
  200. ! ------------------------------------------
  201. @ORIGINATE "ARA"
  202.   SerReset Val("^5"),0,8,1
  203.   Jsr 80
  204. !
  205. ! Set the common options
  206.   Jsr 70
  207. !
  208. ! Set the communication options:
  209.   Jsr 75
  210. !
  211. ! dial the number
  212.   Write "ATD^1\r"
  213. !
  214. ! Wait for a modem response
  215.   Jsr 90
  216.   IfStr C 30 "DATA"
  217.   Write "\r"
  218.   Exit -6019
  219.  
  220. ! ------------------------------------------
  221. ! Originating a call through the "DATA" subport
  222. ! ------------------------------------------
  223. @ORIGINATE "Data" ("\r\nLineShare Line is Busy\r\nBUSY\r\n")
  224.   SerReset 19200,0,8,1
  225.   Jsr 80
  226. !
  227. ! Set the common options
  228.   Jsr 70
  229. !
  230. ! Set the communication options:
  231.   Jsr 75
  232. !
  233. ! dial the number
  234.   Write "ATD^1\r"
  235.   HsReset *
  236. !
  237. ! Wait for a modem response
  238.   Jsr 90
  239.   IfStr C 35 "DATA"
  240.   Write "\r"
  241.   Exit -6019
  242.  
  243. ! ------------------------------------------
  244. ! Originating a call through the "Fax" subPort
  245. ! ------------------------------------------
  246. @ORIGINATE "Fax" ("\r\nLineShare Line is Busy\r\nBUSY\r\n")
  247. !
  248. ! Set the "Fax" speed
  249. !
  250.   SerReset 19200,0,8,1
  251.   Jsr 80
  252. !
  253. ! Set the common options
  254. !
  255.   Jsr 70
  256.   GetOption A "SWHS" 6
  257. !
  258. ! Set the Fax mode (Xon/Xoff)
  259.   Write "AT^A+FCLASS=1\r"
  260.   Jsr 100
  261. !
  262. ! Now emit all commands that the application has sent to that port,
  263. ! except "+FCLASS", etc
  264. !
  265.   EmitClear "FCLASS","V","X","E"
  266.   Jsr 60
  267. !
  268. ! Prepare to receive all error result codes, dial the number
  269. !
  270.   Write "ATV0D^1\r"
  271.   HsReset *
  272.   Jsr 85
  273.   IfStr C 45 "FAX"
  274.   Write "\r"
  275.   Exit -6019
  276. !
  277. !
  278. ! This section emits all modem commands sent from the client application
  279. ! For each set of commands the "OK" answer is awaited
  280. !
  281. @Label 60
  282.   EmitStart
  283. @Label 61
  284.   EmitCommand 62
  285.   Jsr 100
  286.   Jump 61
  287. @Label 62
  288.   return
  289. !
  290. ! This section initiates the modem before ANSWER and ORIGINATEs:
  291. ! extended responses + connect at the highest rate + speaker control +
  292. ! reset on Dtr drop + DCD valid
  293. ! Verbal responses mode, no echo 
  294. !
  295. @Label 70
  296.   Write "AT&D2&C1V1E0\r"
  297.   Jsr 100
  298.   return 
  299.  
  300. ! Set the communication options:
  301. ! • Normal/AUTO Connection
  302. ! • HW flow control  (for ARA, Fax should not use a handshake on receiving)
  303. ! • CONNECT <DCE speed> or CARRIER/CONNECT
  304. @Label 75
  305.   GetOption A "HWHS" 6
  306.   GetOption B "^3" 6
  307.   GetOption C "LNRS" 6
  308.   Write "AT^A^B^C\r"
  309.   Jump 100
  310.  
  311. !
  312. ! This section syncronize the modem after the serial port speed switching
  313. !
  314. @Label 80
  315.   ChrDelay 1
  316.   Write "AT\r"
  317.   ChrDelay 0
  318.   Jsr 100
  319.   return
  320. !
  321. ! Error Codes
  322. @Label 81
  323.   exit -6020
  324. @Label 82
  325.   exit -6022
  326. @Label 83
  327.   exit -6021
  328. @Label 84
  329.   exit -6023
  330.  
  331. !
  332. ! Connecting in the numeric mode (fax)
  333. ! On exit:
  334. ! ^C contains "NONE" if no connection has been established
  335. @Label 85
  336.   MatchClr
  337.   MatchStr 1 88 "1\r"
  338.   MatchStr 2 87 "2\r"
  339.   MatchStr 5 81 "6\r"
  340.   MatchStr 6 82 "7\r"
  341.   MatchStr 7 83 "3\r"
  342.   MatchStr 8 84 "8\r"
  343. @Label 86
  344.   Matchread 1200
  345.   SetVar C "NONE"
  346.   return
  347.  
  348. @Label 87
  349.   Note "Ring…"
  350.   Jump 86
  351. @Label 88
  352.   SetVar C "FAX"
  353.   return
  354.  
  355. !
  356. ! This subroutine waits for the modem response (data mode)
  357. ! On exit:
  358. ! ^A contains the protocol used
  359. ! ^B contains the carrier speed
  360. ! ^C contains "NONE" if no connection has been established
  361. ! If modem reports an error, the scripts exits with an error code
  362. !
  363. @Label 90
  364.   SetVar A "NONE"
  365.   SetVar B ""
  366.   MatchClr
  367.   Matchstr 1 92 "CARRIER ^$\r\n"
  368.   Matchstr 2 93 "PROTOCOL: ^$\r\n"
  369.  
  370.   Matchstr 4 95 "CONNECT ^$/"
  371.   Matchstr 5 97 "CONNECT ^$\r\n"
  372.   Matchstr 6 94 "RING\r\n"
  373.   Matchstr 10 82 "BUSY\r\n"
  374.   MatchStr 11 83 "NO CARRIER\r\n"
  375.   MatchStr 12 84 "NO ANSWER\r\n"
  376. @Label 91
  377.   Matchread 1200
  378.   SetVar C "NONE"
  379.   return
  380.  
  381. @Label 92
  382.   SetVar B "^$"
  383.   Jump 91
  384. @Label 93
  385.   SetVar A "^$"
  386.   Jump 91
  387. @Label 94
  388.   Note "Ring…"
  389.   Jump 91
  390.  
  391.  
  392. ! CONNECT xxxx/XXXX was detected
  393. @Label 95
  394.   Jsr 98
  395.   MatchClr
  396.   MatchStr 1 96 "^$\r\n"
  397.   MatcRead 10
  398. @Label 96
  399.   SetVar A "^$"
  400.   SetVar C "DATA"
  401.   return
  402.  
  403. ! CONNECT xxx was detected
  404. @Label 97
  405.   Jsr 98
  406.   SetVar C "DATA"
  407.   return
  408.  
  409. @Label 98
  410.   ifStr B 99 ""
  411.   return
  412. @Label 99
  413.   SetVar B "^$"
  414.   return 
  415.  
  416. !
  417. ! Processing an AT command:
  418. ! OK -> proceed
  419. ! ERROR or TimeOut ->exit -6019
  420. ! It can be called AFTER the "Write" command, since LineShare buffers input
  421. !
  422. @Label 100
  423.   MatchClr
  424.   MatchStr 1 103 "\r\nOK\r\n"
  425.   MatchStr 2 102 "\r\nERROR\r\n"
  426. @Label 101
  427.   MatchRead 20
  428. @Label 102
  429.   Exit -6019
  430. @Label 103
  431.   return
  432.  
  433. !
  434. ! Processing an AT command in the numeric mode
  435. ! OK -> proceed
  436. ! ERROR or TimeOut ->exit -6019
  437. ! It can be called AFTER the "Write" command, since LineShare buffers input
  438. !
  439. @Label 110
  440.   MatchClr
  441.   MatchStr 1 103 "0\r"
  442.   MatchStr 2 102 "4\r"
  443.   Jump 101
  444.